// 引入全局声明
/// <reference lib="es2020" />

// 假设有两个异步函数
function asyncFunction1() {
    return new Promise((resolve, reject) => {
        const isSuccess = Math.random() > 0.5; // 50% chance of success
        setTimeout(() => {
            isSuccess ? resolve('Result from asyncFunction1') : reject('asyncFunction1 failed');
        }, 1000);
    });
}

function asyncFunction2() {
    return new Promise((resolve, reject) => {
        const randomNum = Math.random();
        const isSuccess = randomNum > 0.3; // 50% chance of success
        setTimeout(() => {
            isSuccess ? resolve(randomNum) : reject('asyncFunction2 failed');
        }, 1500);
    });
}




// 使用 allSettled 扩展方法
const promises = [asyncFunction1(), asyncFunction2()];

Promise.race(promises)
    .then(winner => console.log(winner))
    .catch(error => console.error(error));